<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>您好Springboot</title>
    <%--<script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>--%>
    <script type="text/javascript" src="../js/jquery-3.4.1.min.js">

    </script>
</head>
<body>
<table border="1px" width="65%" align="center">
    <tr>
        <td colspan="6" align="center"><h3>学生信息</h3></td>
    </tr>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th></th>
    </tr>

    <c:forEach items="${userList}" var="u">
        <tr>
            <th>${u.id}</th>
            <th>${u.name}</th>
            <th>${u.age}</th>
            <th>${u.sex}</th>
        </tr>
    </c:forEach>
</table>
</body>

<script type="text/javascript">
    $(function () {
       /* $.get("/userAjax",function (data) {
            /!*for (let i=0;i<data.length;i++){
                let user=data[i];
                console.log(user.name)
            }*!/
           /!* for (let index in data){
                let name=index.name
                console.log(name)
            }*!/
            let tr=''
            for (let user of data){
                // console.log("of",user)
                let name=user.name
                let id=user.id
                let age=user.age
                let sex=user.sex
                tr+="<tr align='center'><td>"+id+"</td><td>"+name+"</td><td>"+age+"</td><td>"+sex+"</td></tr>"
            }
            $("table").append(tr)
        })*/
        $.ajax({
            error: function (data) {
                alert("未知错误！")
            },
            type:"get",
            url:"/userAjax",
            data:{"id":100,"name":"tomcat"},
            success:function (data) {
                let tr=''
                for (let user of data){
                    console.log("of",user)
                    let name=user.name
                    let id=user.id
                    let age=user.age
                    let sex=user.sex
                    tr+="<tr align='center'><td>"+id+"</td><td>"+name+"</td><td>"+age+"</td><td>"+sex+"</td></tr>"
                }
                $("table").append(tr)
            }

        })
    });
</script>


</html>